# HTML DOM nodeValue Property

Element Object

## Example

Get the node value of the first <button> element in the document:

var x = document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;

The result of x will be:

Try it yourself
Try it yourself »

More "Try it Yourself" examples below.

## Definition and Usage

The nodeValue property sets or returns the node value of the specified node.

If the node is an element node, the nodeValue property will return null.

Note: If you want to return the text of an element, remember that text is always inside a Text node, and you will have to return the Text node's node value (element.childNodes[0].nodeValue).

For other node types, the nodeValue property will return different values for different node types.

Tip: An alternative to the nodeValue property can be the textContent property.

## Browser Support

Property |  |  |  |  |
--- | --- | --- | --- | --- | ---
nodeValue | Yes | Yes | Yes | Yes | Yes

## Syntax

Return the node value:

node.nodeValue

Set the node value:

node.nodeValue=value

## Property Values

Value | Description
--- | ---
value | Specifies the node value of the specified node

## Technical Details

Return Value:

A String, representing the value of the node.

Possible values:

- Returns null for element nodes and document nodes
- Returns the value of the attribute for attribute nodes
- Returns the content for text nodes
- Returns the content for comment nodes

DOM Version | Core Level 1 Node Object

## More Examples

## Example

Get the node name, node value and the node type of the <div> element's first child node:

<div id="myDIV">This is a div element.</div>
<script>
var x = document.getElementById("myDIV").firstChild;
var txt = "";
txt += "The node name: " + x.nodeName + "<br>";
txt += "The node value: " + x.nodeValue + "<br>";
txt += "The node type: " + x.nodeType;
</script>

The result of txt will be:

The node name: #text
The node value: This is a div element.
The node type: 3
Try it yourself »

## Related Pages

HTML DOM reference: node.nodeName Property

HTML DOM reference: node.nodeType Property

HTML DOM reference: node.nodeValue Property

HTML DOM reference: node.childNodes Property

Element Object

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples